import java.util.ArrayList;
/*
 * Bob Dayton
 * COSC - 716 Assignment 2
 * The HeartHealthy iterator returns only 
 * items that have the heartHealthy variable set to true
 */

public class HeartHealthyMenuIterator implements MenuIterator{

	//private MenuItem[] items;
	private ArrayList<MenuItem> items = new ArrayList<MenuItem>();
	private int count;
	private int current;
	
	public HeartHealthyMenuIterator(ArrayList<MenuItem> i)
	{
		items = i;
		count = 0;		
		current = 0;
	}
	
	@Override
	public MenuItem next() {
		
		setNext();
		return items.get(current);
	}

/*
 * hasNext() will check to see
 * if there are more menu items in the array
 * that are heart healthy or not
 */
	@Override
	public boolean hasNext() {
		boolean found = false;
		/*
		 * since we just want to know if there is a next item
		 * we will use a temporary count variable instead
		 * of updating our actual count variable 
		 */
		int tempCount = count;
			while(!found && tempCount < items.size())
			{
				if(items.get(tempCount) != null)		
				{
					if(items.get(tempCount).isHeartHealthy() != true)
					{
						tempCount++;
					}
					else
					{
						//current = count;
						tempCount++;
						found = true;
					}
				}
			}
		
		return found;
	}
	
	/*
	 * setNext() sets the next item for the iterator to return
	 */
	private void setNext()
	{
		boolean found = false;
		
		while(!found && count < items.size())
		{
			if(items.get(count) != null)		
			{
				if(items.get(count).isHeartHealthy() != true)
				{
					count++;
				}
				else
				{
					current = count;
					count++;
					found = true;
				}
			}
		}
	}

}
